package com.qf.springboot230203.ex;

import com.baomidou.kaptcha.exception.KaptchaIncorrectException;
import com.baomidou.kaptcha.exception.KaptchaNotFoundException;
import com.baomidou.kaptcha.exception.KaptchaTimeoutException;
import com.qf.springboot230203.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
public class MyRestExHandler {

    @Autowired
    OnepieceException onepieceException;

    @ExceptionHandler(KaptchaTimeoutException.class)
    public ResultVo TimeoutException(){

        return ResultVo.error("请求超时");
    }

    @ExceptionHandler(KaptchaIncorrectException.class)
    public ResultVo IncorrectException(){

        return ResultVo.error("验证码输入有误");
    }

    @ExceptionHandler(KaptchaNotFoundException.class)
    public ResultVo notFoundException(){

        return ResultVo.error("未找到验证码");
    }

    @ExceptionHandler(OnepieceException.class)
    public Map<String,String> sameNameException(){

        HashMap<String, String> map = new HashMap<>();

        map.put("code",onepieceException.getCode());

        map.put("msg",onepieceException.getMsg());

        return map;
    }
}
